/**
 * @author 明明
 * @E-mail zsm@bym.name
 * @version 创建时间:2014年12月25日 上午10:47:49
 */
package cn.xspace.module.other.http;
import org.json.JSONException;
import org.json.JSONObject;

import com.android.volley.Request.Method;
import com.android.volley.RequestQueue;
import com.android.volley.Response.ErrorListener;
import com.android.volley.Response.Listener;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.Volley;
import com.xspace.android.xafcommon.util.Constants;

import android.content.Context;
import android.os.Handler;
import android.os.Message;

public class RegisterCodeIFHTTP {
	public Handler handler;
	private Context context;
	private JSONObject requestObj;

	public RegisterCodeIFHTTP(Context context, JSONObject requestObj) {
		this.context = context;
		this.requestObj = requestObj;
	}

	public void sendData() {
		RequestQueue mQueue = Volley.newRequestQueue(context);
		mQueue.add(new JsonObjectRequest(Method.POST, Constants.URL_IFCode, requestObj,
				new Listener<JSONObject>() {
					@Override
					public void onResponse(JSONObject response) {
						Message ms = new Message();
						try {
							int code = response.getInt("code");
							if(code==0){
								ms.obj = response.optString("desc");
							}
							ms.arg1 = code;
							handler.sendMessage(ms);
						} catch (JSONException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
					}
				}, new ErrorListener() {

					@Override
					public void onErrorResponse(VolleyError error) {
						// TODO Auto-generated method stub
						Message ms = new Message();
						ms.arg1 = 100;
						handler.sendMessage(ms);
					}
				}));
		mQueue.start();
	}
}